<?php
namespace App\Admin\Controllers\Traits\WxSettingTraits;


use App\Wen\Utils\GatewayUtils;
use App\Wen\Utils\Settings;
use App\Wen\Utils\SiteUtils;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Widgets\Form;
use Dcat\Admin\Widgets\Tooltip;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

trait formTaokeTrait{
    public function index_taoke(Content $content)
    {
        return $content->title('淘客')
//            ->body($this->buildPreviewButton())
//            ->body($this->newline())
            ->body(
                <<<HTML
<div class="card">{$this->form_taoke()->render()}</div>
HTML
            );
    }
    protected function form_taoke(){
        $form = new Form();
        $form->confirm('您确定要提交表单吗？', 'content');
        $form->disableResetButton();
        $form->tab('大淘客', function (Form $form) {
            $res12 = __system__paycode__tip__(13);
            Tooltip::make('.mini_global_admin_open_not_support_tip')
                ->bottom()
                ->title($res12['tip']);
            $form->text('app_dataoke_appkey', '大淘客appKey')->help($res12['text'].'<a href="https://img.mini.minisns.cn/images/taoke/page/dtk.jpg" target="_blank">配置教程</a>')->default(Settings::get('app_dataoke_appkey', ''));
            $form->text('app_dataoke_appsecret', '大淘客appSecret')->help('<a href="https://img.mini.minisns.cn/images/taoke/page/dtk.jpg" target="_blank">配置教程</a>')->default(Settings::get('app_dataoke_appsecret', ''));
        });
        $form->tab('单页', function (Form $form) {
            $res12 = __system__paycode__tip__(13);
            Tooltip::make('.mini_global_admin_open_not_support_tip')
                ->bottom()
                ->title($res12['tip']);
            $form->text('app_dataoke_realhot_page_appkey', '实时榜单appKey')->help($res12['text'].'先进入“单页市场”，进入<a href="https://www.dataoke.com/kfpt/my-single-detail.html?aid=32" target="_blank">实时榜单</a>单页后，点击一键推广，最后复制appkey，<a href="https://img.mini.minisns.cn/images/taoke/page/realhot.jpg" target="_blank">配置教程</a>')->default(Settings::get('app_dataoke_realhot_page_appkey', ''));
            $form->text('app_dataoke_flashsale_page_appkey', '限时抢购appKey')->help('先进入“单页市场”，进入<a href="https://www.dataoke.com/kfpt/my-single-detail.html?aid=33" target="_blank">限时抢购</a>单页后，点击一键推广，最后复制appkey')->default(Settings::get('app_dataoke_flashsale_page_appkey', ''));
            $form->text('app_dataoke_billionsubsidy_page_appkey', '百亿补贴appKey[不建议使用]')->help('先进入“单页市场”，进入<a href="https://www.dataoke.com/kfpt/single-detail.html?aid=54" target="_blank">百亿补贴</a>单页后，点击一键推广，最后复制appkey')->default(Settings::get('app_dataoke_billionsubsidy_page_appkey', ''));
            $form->text('app_dataoke_packaging9_9_page_appkey', '9.9包邮appKey')->help('先进入“单页市场”，进入<a href="https://www.dataoke.com/kfpt/single-detail.html?aid=31" target="_blank">9.9包邮页面效果</a>单页后，点击一键推广，最后复制appkey')->default(Settings::get('app_dataoke_packaging9_9_page_appkey', ''));
            $form->text('app_dataoke_threadreport_page_appkey', '线报appKey[不建议使用]')->help('先进入“单页市场”，进入<a href="https://www.dataoke.com/kfpt/single-detail.html?aid=52" target="_blank">线报页面效果</a>单页后，点击一键推广，最后复制appkey')->default(Settings::get('app_dataoke_threadreport_page_appkey', ''));


        });

        $form->tab('京东', function (Form $form) {
            $res13 = __system__paycode__tip__(13);
            Tooltip::make('.mini_global_admin_open_not_support_tip')
                ->bottom()
                ->title($res13['tip']);
            $form->text('app_dataoke_jd_unionId', '京东联盟unionId')->help($res13['text'].'先进入京东联盟，登录后，右上角头像下拉点击进入可以看到联盟id，没看到多找会')->default(Settings::get('app_dataoke_jd_unionId', ''));
        });

        $form->tab('拼多多', function (Form $form) {
            $form->text('app_dataoke_pdd_main_pid', '推广位pid')->help('需要经过推手授权，很难解释清楚，请联系我远程帮你')->placeholder('34368057_273863836')->default(Settings::get('app_dataoke_pdd_main_pid', ''));
        });


        $form->action('settings/action/taoke');
        return $form;
    }

    public function taoke(Request $request)
    {
        SiteUtils::forget_config_data();
        Settings::set('app_dataoke_realhot_page_appkey', $request->input('app_dataoke_realhot_page_appkey'), true);
        Settings::set('app_dataoke_flashsale_page_appkey', $request->input('app_dataoke_flashsale_page_appkey'), true);
        Settings::set('app_dataoke_billionsubsidy_page_appkey', $request->input('app_dataoke_billionsubsidy_page_appkey'), true);
        Settings::set('app_dataoke_packaging9_9_page_appkey', $request->input('app_dataoke_packaging9_9_page_appkey'), true);
        Settings::set('app_dataoke_threadreport_page_appkey', $request->input('app_dataoke_threadreport_page_appkey'), true);

        Settings::set('app_dataoke_jd_unionId', $request->input('app_dataoke_jd_unionId'), true);
        Settings::set('app_dataoke_pdd_main_pid', $request->input('app_dataoke_pdd_main_pid'), true);



        Settings::set('app_dataoke_appkey', $request->input('app_dataoke_appkey'), true);
        Settings::set('app_dataoke_appsecret', $request->input('app_dataoke_appsecret'), true);

        $__global_config_version__ = Settings::get('__global_config_version__', 1) + 1;
        Settings::set('__global_config_version__', $__global_config_version__);
        GatewayUtils::success('all', 13, [ 'version' => $__global_config_version__, 'file' => basename(__FILE__) ]);
        return $this->response()->success('成功！');
    }
}
